package com.xuetang9.t9.hotel.controller;

import com.xuetang9.t9.hotel.beans.EFoodcategory;
import com.xuetang9.t9.hotel.services.IGoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName GoryController
 * @Description TODO
 * @Author qin
 * @Date 2020/2/24 17:12
 * @Version 1.0
 **/
@Controller
@RequestMapping("gory")
public class GoryController {
    @Autowired
    private IGoryService goryService;

    @GetMapping("list")
    @ResponseBody
    public List<EFoodcategory> list(){
        return goryService.goryList();
    }

    @PostMapping("insert")
    @ResponseBody
    public  List<EFoodcategory> insert(@RequestParam("name")String name,@RequestParam("count")String count){
        int id = goryService.goryCount()+1;
        EFoodcategory foodcategory = new EFoodcategory(id,name,Long.valueOf(count));
        goryService.insertGory(foodcategory);
        return goryService.goryList();
    }

    @PostMapping("update")
    @ResponseBody
    public List<EFoodcategory> update(@RequestParam("id")String id,@RequestParam("name")String name,@RequestParam("count")String count){
        EFoodcategory foodcategory = new EFoodcategory(Long.valueOf(id),name,Long.valueOf(count));
        goryService.updateGory(foodcategory);
        return goryService.goryList();
    }


    @PostMapping("delete")
    @ResponseBody
    public List<EFoodcategory> delete(@RequestParam("id")Integer id){
        System.out.println(id);
        goryService.deleteGory(id);
        return goryService.goryList();
    }

    /**
     * 检索全部分类菜品
     * @return
     */
    @RequestMapping("/showall")
    @ResponseBody
    public List<EFoodcategory> queryByAll(){
        return goryService.queryByAll();
    }

}
